//用户收藏
exports.add_comment = function (req, res) {

    //获取bodyParams参数
    var bodyParams = req.routeInfo.bodyParams;
    // ////console.log(bodyParams);

    //最终结果
    var resultData = {};

    var forumActivityData = 0;
    //任务流创建
    async.waterfall([
            //1.论坛评论添加
            function (cb) {
                R.SEND_HTTP(
                    req,
                    {
                        url: CORE_APIConfig.coreAPI.addActivityComment,
                        method: 'POST',
                        data: {
                            fac_faid: bodyParams.fac_faid,
                            fac_uid: bodyParams.fac_uid,
                            fac_content: bodyParams.fac_content,
                            fac_reply_uid: bodyParams.fac_reply_uid == undefined ? 0 : bodyParams.fac_reply_uid,
                            fac_is_reply: bodyParams.fac_is_reply == undefined ? 0 : bodyParams.fac_is_reply,
                            fac_fid: bodyParams.fac_fid == undefined ? 0 : bodyParams.fac_fid,
                        }
                    },
                    function (err, data) {
                        ////console.log(data);
                        //判断是否有错误信息
                        if (err) {
                            return RES.response(res, false, "评论发布失败");
                        }

                        resultData = data;
                        cb();
                    }
                );

            },
            //2.活动信息查询
            function (cb) {
                R.SEND_HTTP(
                    req,
                    {
                        url: CORE_APIConfig.coreAPI.searchForumActivity + "/fa_id/" + bodyParams.fac_faid,
                        method: 'POST',
                        data: {
                            fields: ["fa_id", "fa_comment_count"].join(",")
                        }
                    },
                    function (err, data) {
                        ////console.log(data);
                        //判断是否有错误信息
                        if (err) {
                            return RES.response(res, false, data);
                        }

                        forumActivityData = data.data;
                        cb();
                    }
                );

            },
            //3.论坛活动评论数更新
            function (cb) {
                if (bodyParams.fac_fid > 0) {
                    cb();
                } else {
                    R.SEND_HTTP(
                        req,
                        {
                            url: CORE_APIConfig.coreAPI.updateActivity,
                            method: 'POST',
                            data: {
                                fa_id: bodyParams.fac_faid,
                                fa_comment_count: parseInt(forumActivityData[0].fa_comment_count) + 1
                            }
                        },
                        function (err, data) {
                            //判断是否有错误信息
                            if (err) {
                                return RES.response(res, false, "评论数更新失败");
                            }

                            resultData = data;
                            cb();
                        }
                    );
                }


            },

        ], function (err, result) {

            //返回最终拼接结果
            RES.response(res, true, resultData);

        }
    );

}